package com.borened.netty.protocol.mqtt;

import io.netty.channel.Channel;
import lombok.Data;

import java.util.Objects;

/**
 * mqtt客户端会话
 */
@Data
public class MqttClientSession {

    private String clientId;
    private boolean cleanSession;
    private int keepAlive;

    /**
     * 信道
     */
    private Channel channel;

    public MqttClientSession(String clientId, boolean cleanSession, int keepAlive, Channel channel) {
        this.clientId = clientId;
        this.cleanSession = cleanSession;
        this.keepAlive = keepAlive;
        this.channel = channel;
    }

    @Override
    public String toString() {
        return "MqttClient{" +
                "clientId='" + clientId + '\'' +
                ", cleanSession=" + cleanSession +
                ", keepAlive=" + keepAlive +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MqttClientSession that = (MqttClientSession) o;
        return cleanSession == that.cleanSession && keepAlive == that.keepAlive && Objects.equals(clientId, that.clientId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(clientId, cleanSession, keepAlive);
    }
}